#include <workflow/WFTaskFactory.h>
#include <workflow/WFFacilities.h>
#include <stdio.h>
#include <signal.h>

std::string web_url = "http://www.taobao.com";
std::string redis_url = "*";
WFFacilities::WaitGroup waitGroup(1);


void handler(int) {
    waitGroup.done();
    printf("done\n");
}

void fetchWebpage(WFHttpTask *task) {
    const void *body;
    size_t size;
    task->get_resp()->get_parsed_body(&body, &size);

    WFRedisTask *redis_task = WFTaskFactory::create_redis_task(redis_url, 3, NULL);
    redis_task->get_req()->set_request("set", {"taobao", (const char *) body});
    series_of(task)->push_back(redis_task);
}

int main(void) {
    signal(SIGINT, handler);

    WFHttpTask *task = WFTaskFactory::create_http_task(web_url, 10, 10, fetchWebpage);

    task->start();
    waitGroup.wait();
    return 0;
}

